package com.yuandian.po;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

/**
 * 文档导出申请表单
 * @author User
 *
 */
public class DocumentExportApplicationForm<T> {

    /**
     * 文档下载按钮，所处在那个服务下
     */
    private String serviceName ;
    /**
     * 文档下载按钮，所处在那个服务下，那个模块下
     */
    private String moduleName ;
    /**
     * 文档下载按钮名称
     */
    private String exportButtomName;
    /**
     * 文档导出，服务端处理文档所需参数，参数格式：默认使用json格式
     */
    private String docExportParameterJson;
    /**
     * 任务任务处理成功时，生成的文档，文档名称
     */
    private String exportFileName;
    /**
     * 文档导出，服务端处理文档处理类
     */
    private String serviceCode;
    /**
     * 文档导出，服务端处理文档处理类中，方法名称
     */
    private Integer docHandleType;

	public String getServiceCode() {
		return serviceCode;
	}

	public void setServiceCode(String serviceCode) {
		this.serviceCode = serviceCode;
	}

	public Integer getDocHandleType() {
		return docHandleType;
	}

	public void setDocHandleType(Integer docHandleType) {
		this.docHandleType = docHandleType;
	}

	/**
	 * 文档导出参数对象
	 */
	private T params;

	public DocumentExportApplicationForm() {
		super();
		// TODO Auto-generated constructor stub
	}

	public DocumentExportApplicationForm(String serviceName, String moduleName, String exportButtomName,
                                         String docExportParameterJson, String exportFileName, String docHandleClass, String docHandleMethod) {
		super();
		this.serviceName = serviceName;
		this.moduleName = moduleName;
		this.exportButtomName = exportButtomName;
		this.docExportParameterJson = docExportParameterJson;
		this.exportFileName = exportFileName;
		this.docHandleType = docHandleType;
		this.serviceCode = serviceCode;
	}

	public void setParams(T t){
		try {
			this.setDocExportParameterJson(new ObjectMapper().writeValueAsString(t));
		} catch (JsonProcessingException e) {
			e.printStackTrace();
		}
	}

	public T getParams(Class<T> clazz){
		if(this.params == null){
//			this.params = (T) JacksonUtil.parseObject(this.docExportParameterJson, clazz);
		}
		return this.params;
	}

	public String getServiceName() {
		return serviceName;
	}

	public void setServiceName(String serviceName) {
		this.serviceName = serviceName;
	}

	public String getModuleName() {
		return moduleName;
	}

	public void setModuleName(String moduleName) {
		this.moduleName = moduleName;
	}

	public String getExportButtomName() {
		return exportButtomName;
	}

	public void setExportButtomName(String exportButtomName) {
		this.exportButtomName = exportButtomName;
	}

	public String getDocExportParameterJson() {
		return docExportParameterJson;
	}

	public void setDocExportParameterJson(String docExportParameterJson) {
		this.docExportParameterJson = docExportParameterJson;
	}

	public String getExportFileName() {
		return exportFileName;
	}

	public void setExportFileName(String exportFileName) {
		this.exportFileName = exportFileName;
	}


	@Override
	public String toString() {
		return "DocumentExportApplicationForm [serviceName=" + serviceName + ", moduleName=" + moduleName
				+ ", exportButtomName=" + exportButtomName + ", docExportParameterJson=" + docExportParameterJson
				+ ", exportFileName=" + exportFileName + ", serviceCode=" + serviceCode + ", docHandleType="
				+ docHandleType + "]";
	}
}
